<template>
	<!-- 全真模拟-在线组卷-手动组卷【设置题型】 -->
	<view>
		<u-navbar back-icon-color="#fff" :isFixed="true" :border-bottom="false" title="考试通知" title-color="#FFFFFF">
		</u-navbar>
		<view class="form-item">
			<view class="title">
				<text>通知标题</text>
			</view>
			<view class="input-container">
				<input type="text" v-model="noticeTitle"  placeholder="通知标题" />
			</view>
		</view>
		<view class="form-item">
			<view class="title">
				<text>通知内容</text>
			</view>
			<view class="input-container">
				<textarea type="text" v-model="noticeContent"  placeholder="请输入通知内容"></textarea>
			</view>
		</view>
		<view class="button confirm" @click="submit" shape="circle" >发布考试</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
		  noticeTitle:'',//通知标题
			noticeContent:'',//通知内容
			clickFirst:true
		};
	},
	onLoad(){
		 const  getInfo=uni.getStorageSync('examStorage')
		 this.noticeTitle=getInfo.examname+"考试通知";
		 this.noticeContent="请于"+getInfo.starttime+"准时参加"+getInfo.examname+"！此场考试的截止日期为"+getInfo.endtime+",请合理安排时间，切莫错过考试！"
	},
	methods: {
		submit() {
			if(this.noticeTitle && this.noticeContent && this.clickFirst){
				const sess=uni.getStorageSync('examStorage')
				sess.noticeTitle=this.noticeTitle;
				sess.noticeContent=this.noticeContent;
				sess.examcha=1;
				this.clickFirst=false;
				return new Promise((resolve, reject) => {
					this.request
						.post('/app/teacher/releaseExam/addAndUpdateExam',sess)
						.then(res => {
							uni.showToast({
								icon: 'success',
								title: '发布成功！'
							});
							uni.switchTab({
								url:'./exam'
							})
							this.clickFirst=true
							resolve();
						})
						.catch(reject);
				});
			}else{
				uni.showToast({
					icon: 'none',
					title: '通知信息不能为空！'
				});
			}
		},
	}
};
</script>
<style>
page {
	background-color: #f5f5f5;
}
</style>
<style lang="scss">
.confirm {
	font-size: 30upx;
	font-weight: 400;
	background: $linear-bg;
	border: none;
	color: #ffffff;
	width:350upx;
	height: 76upx;
	margin: 0 auto;
	text-align: center;
	border-radius: 76upx;
	line-height: 76upx;
	margin-top: 240upx;
}
.title {
	line-height: 100upx;
	font-size: 30upx;
	font-weight: 400;
	color: #636874;
	text:last-child {
		color: #a9abb0;
	}
}
.form-item > * {
	padding: 0 30upx;
}
.input-container {
	display: flex;
	align-items: center;
	background-color: #ffffff;
	textarea{
		width: 100%;
		margin: 30upx 0;
	}
	input {
		height: 110upx;
		font-size: 32upx;
		text-align: left;
		position: relative;
		flex: 1;
	}
}
</style>
